using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication11.Models.Mapping
{
    public class roleprivilegeMap : EntityTypeConfiguration<roleprivilege>
    {
        public roleprivilegeMap()
        {
            // Primary Key
            this.HasKey(t => new { t.role_id, t.privilege_id });

            // Properties
            this.Property(t => t.role_id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.privilege_id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.privilege_action)
                .HasMaxLength(1);

            // Table & Column Mappings
            this.ToTable("roleprivilege");
            this.Property(t => t.role_id).HasColumnName("role_id");
            this.Property(t => t.privilege_id).HasColumnName("privilege_id");
            this.Property(t => t.privilege_action).HasColumnName("privilege_action");

            // Relationships
            this.HasRequired(t => t.privilege)
                .WithMany(t => t.roleprivileges)
                .HasForeignKey(d => d.privilege_id);

        }
    }
}
